<template lang="html">
  <div class="contain-body clearfix">
    <el-form ref="form" :model="form" label-width="140px">
      <el-form-item label="企业名称（法人）：">
        <el-input v-model="form.name" placeholder='请输入' class="pull-left" style="width: 20%"></el-input>
        <div class="el-button el-button--theme pull-left" @click='getList'>搜索</div>
        <div class="el-button el-button--theme pull-right"><router-link to='./add'>新增企业</router-link></div>
      </el-form-item>
    </el-form>
    <div class="all-cont">
      <el-table
        :data="tableData"
        v-loading='listLoading'
        element-loading-text="再点我就刷给你看！。。。"
        border
        style="width: 100%">
        <el-table-column prop="name" label="企业名称">
        </el-table-column>
        <el-table-column prop="corporation" label="法人">
        </el-table-column>
        <el-table-column prop="address" label="公司地址">
        </el-table-column>
        <el-table-column prop="creation_date" label="创建日期">
        </el-table-column>
        <el-table-column prop="lastEditor" label="最后操作日期">
        </el-table-column>
        <el-table-column prop="lastTime" label="最后操作者">
        </el-table-column>
        <!--<el-table-column label="企业关联信息">-->
          <!--<template scope="scope">-->
            <!--<router-link class='el-button&#45;&#45;text' :to="{path: 'about', query: { id: scope.row.id}}">企业关联数据</router-link>-->
          <!--</template>-->
        <!--</el-table-column>-->
        <el-table-column label="操作">
          <template scope="scope">
            <el-button type="text">
              <router-link :to="{path: 'add', query: {id: scope.row.id}}">
                <i class="glyphicon glyphicon-edit el-button--text"></i>
              </router-link>
            </el-button>
            <el-button type="text" @click="deleteCompany(scope.row.id)">
              <i class="glyphicon glyphicon-delete"></i>
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination @current-change='this.changeCurrent' layout="prev, pager, next" :total="this.total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  props: ['data'],
  data () {
    return {
      form: {
          name: '',
          page: 1
      },
      total: 1000,
      listLoading: false,
      tableData: []
    }
  },
  mounted () {
    this.data.title = '企业列表'
    this.getList()
  },
  methods: {
    changeCurrent (current) {
      this.form.page = current
      this.getList()
    },
    deleteCompany (id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http('delete', 'company', {id: id})
        .then((data) => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.getList()
        })
      }).catch(() => {
        this.$message.error('删除错误~鬼知道你经历了什么╮(╯▽╰)╭')
      })
    },
    getList () {
      this.listLoading = true
      this.$http('get', 'search', this.form)
      .then((data) => {
        this.listLoading = false
        this.total = data.result.total
        this.tableData = data.result.dataList
      })
    }
  }
}
</script>

<style lang="less">
a{
  text-decoration: none;
}
</style>
